<?php

namespace App\Models\GameDB\LotteryDraw;

use Illuminate\Database\Eloquent\Model;

class CheckRecord extends Model
{
    public $connection = 'mysql_game';

    protected $table = 'lottery_pet_draw_check_record';

    protected $primaryKey = 'id';

    public $timestamps = true;

    public function gift()
    {
        return $this->hasOne('App\Models\MainDB\Gift','id','gift_id');
    }

    public function user_data()
    {
        return $this->hasOne('App\Models\MainDB\UserData','user_id','user_id');
    }

    /**
     * @param $data
     */
    public function addRecord($data)
    {
        $game_user_model = app('model_lottery_pet_pool_user');
        //游戏盈利判定、当盈利金额达到设置的止盈金额时，将修正池次数清0
        if ($data['clear_money'] > 0) {
            $game_user = $game_user_model->where('user_id', $data['user_id'])->first();
            $data['add_count'] = 0 - $game_user->sup_count;
            $game_user->sup_count = 0;
            $game_user->save();
        }
        if ($data['add_count'] > 0) {
            $game_user_model->where('user_id', $data['user_id'])->increment('sup_count', $data['add_count']);
        }
        $this->insert($data);
    }

}
